<%= render 'admin/nav' %>
<% title 'Stats - Libraries.io' %>
<h1>
  Stats
</h1>

<div class="row">
  <div class="col-md-12">
    <h5><strong>Recent Signups</strong></h5>
    <% @recent_users.each do |user| %>
      <%= image_tag(user.avatar_url(120), width: 60, height: 60, alt: user, class: 'pull-left') %>
    <% end %>
  </div>
</div>
<div class="row">
  <div class="col-md-6">
    <h5><strong>Recent Subscriptions</strong></h5>
    <% @recent_subscriptions.each do |sub| %>
      <div style='min-height:30px;'>
        <% if sub.user %>
        <%= link_to image_tag(sub.user.avatar_url(40), width: 20, height: 20, alt: sub.user, class: 'pull-left'), user_path(sub.user.to_param), class: 'tip', style: 'display:block; float:left; margin-right:5px;', title: "#{sub.user.nickname}: #{pluralize(sub.user.subscriptions.count, 'subs')}, #{pluralize(sub.user.all_repositories.count, 'repo')}, #{pluralize(sub.user.repository_subscriptions.count, 'track')}" %>
         <%= link_to sub.user, user_path(sub.user.to_param) %>
        <% else %>Deleted<% end %>
        subscribed to <%= link_to sub.project, project_path(sub.project.to_param) %>
        <br>
        <small>
          <%= timeago_tag(sub.created_at) %>
        </small>
      </div>
    <% end %>
  </div>
  <div class="col-md-6">
    <h5><strong>Recent Repo Subscriptions</strong></h5>
    <% @recent_watches.each do |sub| %>
      <div style='min-height:30px;'>
        <% if sub.user %>
        <%= link_to image_tag(sub.user.avatar_url(40), width: 20, height: 20, alt: sub.user, class: 'pull-left'), user_path(sub.user.to_param), class: 'tip', style: 'display:block; float:left; margin-right:5px;', title: "#{sub.user.nickname}: #{pluralize(sub.user.subscriptions.count, 'subs')}, #{pluralize(sub.user.all_repositories.count, 'repo')}, #{pluralize(sub.user.repository_subscriptions.count, 'track')}" %>
         <%= link_to sub.user, user_path(sub.user.to_param) %>
        <% else %>Deleted<% end %>
        watched
        <% if sub.repository %>
        <%= link_to sub.repository, repository_path(sub.repository.to_param) %>
        <% else %>deleted repo<% end %>
        <br>
        <small>
          <%= timeago_tag(sub.created_at) %>
          <% if sub.repository %>
            - <%= link_to pluralize(sub.repository.repository_dependencies.count, 'dependencies'), repository_path(sub.repository.to_param.merge(anchor: 'dependencies')) %>
          <% end %>
        </small>
      </div>
    <% end %>
  </div>
</div>
<hr>
<div class="row">
  <%= stats_for('Users', @new_users) %>
  <%= stats_for('Subscriptions', @new_subscriptions) %>
  <%= stats_for('Packages', @new_projects) %>
  <%= stats_for('Versions', @new_versions) %>
</div>

<div class="row">
  <%= stats_for('Repo Subscriptions', @new_repo_subs) %>
  <%= stats_for('Web Hooks', @new_web_hooks) %>
</div>
